<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="../base/head.jsp"%>
<html>
<head>
<script type="text/javascript">
	
   function fun1(){
	   var dataStr = '{"a":"abc","b":"def","name":"xxxxxx","pwd":"yyyyyyy"}';
	   var data = $.parseJSON(dataStr);
	   
	   $.ajax({
			type:"POST",
			url:"<%=basePath%>catalog/processSubmit.do", 
			data:data, 
			success:function(data){  
		        alert('success......!' + data.body.pojo.a); 
		    },
			error:function(XMLHttpRequest, textStatus, errorThrown) {
				document.write("json " + textStatus + XMLHttpRequest.responseText);
			}
		});
	   
   }	
   
   
   function fun2(){
	   var dataStr = '{"name":"chenhs","pwd":"123456"}';
	   var data = $.parseJSON(dataStr);
	   
	 //  alert(data.name);
	 //  alert(data.pwd);
	   
	   $.ajax({  
		    type: "POST",  
		    url: "<%=basePath%>catalog/processSubmit1.do",  
		    data: data,  
		    success: function(data){  
		        alert("yes..." + data.body.name + ", " + data.body.pwd);
		    },  
		    error: function(res){  
		        
		    }  
		}); 

   }
	
   
   function fun22(){
		var idList = new Array();  
		idList.push("1");   
		idList.push("2");   
		idList.push("3");  
		var isBatch = false;  
		
		var dataStr = '{"idList":"'+idList+'","isBatch":'+isBatch+'}';
		var data = $.parseJSON(dataStr);
		
		alert(data.idList);
		alert(data.isBatch);
		
		$.ajax({  
		    type: "POST",  
		    url: "<%=basePath%>catalog/deleteCatalogSchemes.do",
			data : data,
			success : function(data) {
				alert("yes.");
			},
			error : function(res) {

			}
		});
		alert(33333);
	}
   
   //fun33有错误
   function fun33(){
		var data = {pojo:{a:"1111", b:"2222"},users:[{name:"3",pwd:"10"},{name:"4",pwd:"15"}]};
		//var data = $.parseJSON(dataStr);

		$.ajax({  
		    type: "POST",  
		    url: "<%=basePath%>catalog/testUserList1.do",
			data : data,
			dateType : "json",
			success : function(data) {
				alert("yes.");
			},
			error : function(res) {

			}
		});
		alert(9999999);
	}

   //使用postman提交正常，可能此处构造数据有问题
   function fun44(){
       var dataStr = '{"pojo":{"a":"1111", "b":"2222"},"users":[{"name":"3","pwd":"10"},{"name":"4","pwd":"15"}]}';
       var data = $.parseJSON(dataStr);

       $.ajax({
           type: "POST",
           url: "<%=basePath%>catalog/testUserList2.do",
           data : data,
		   dateType: "json",
           success : function(data) {
               alert("yes.");
           },
           error : function(res) {

           }
       });
       alert(1000000000);
   }
</script>

<title>Insert title here</title>
</head>
<body>
	<h1>message:${message}</h1>

	<input type="button" name="fun1" value=" fun1 " onclick="fun1()" />
	<br />
	<input type="button" name="fun2" value=" fun2 " onclick="fun2()" />
	<br />
	<input type="button" name="fun22" value=" fun22 " onclick="fun22()" />
	<br />
	<input type="button" name="fun33" value=" fun33 " onclick="fun33()" />
    <br />
    <input type="button" name="fun44" value=" fun44 " onclick="fun44()" />

	<form action="<%=basePath%>catalog/testUserList.do" method="post">
		<table>
			<thead>
				<tr>
					<th>Name</th>
					<th>Pwd</th>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<td colspan="2"><input type="submit" value="Save" /></td>
				</tr>
			</tfoot>
			<tbody>
				<tr>
					<td><input name="users[0].name" value="aaa" /></td>
					<td><input name="users[0].pwd" value="bbb" /></td>
				</tr>
				<tr>
					<td><input name="users[1].name" value="ccc" /></td>
					<td><input name="users[1].pwd" value="ddd" /></td>
				</tr>
				<tr>
					<td><input name="users[2].name" value="eee" /></td>
					<td><input name="users[2].pwd" value="fff" /></td>
				</tr>
				<tr>
					<td><input name="pojo.a" value="xxxxxxxxx" /></td>
					<td><input name="pojo.b" value="yyyyyyyyy" /></td>
				</tr>
			</tbody>
		</table>
	</form>
	
	<br/><br/><br/>
	
	<form action="<%=basePath%>helloworld/helloWorld.do" method="post">
		<table>
			<thead>
				<tr>
					<th>Name</th>
					<th>Pwd</th>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<td colspan="2"><input type="submit" value="Save" /></td>
				</tr>
			</tfoot>
			<tbody>
				<tr>
					<td><input name="name" value="aaa" /></td>
					<td><input name="pwd" value="bbb" /></td>
				</tr>
			</tbody>
		</table>
	</form>
	
</body>
</html>
